using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace TracerViewer
{
    public partial class Form1 : Form
    {
        TracerLib.Tracer _tracer;

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
        }

        private void button1_Click(object sender, EventArgs e)
        {
            button2.Enabled = false;
            button1.Enabled = false;
            _tracer = new TracerLib.Tracer();
            uint width = System.Convert.ToUInt32(textBox1.Text);
            uint height = System.Convert.ToUInt32(textBox2.Text);

            progressBar1.Maximum = System.Convert.ToInt32(width * height);
            timer1.Enabled = true;
            label3.Text = _tracer.Draw(width, height, richTextBox1.Text + "\n");
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            progressBar1.Value = (int)_tracer.GetCount();
            if (progressBar1.Value == progressBar1.Maximum)
            {
                timer1.Enabled = false;
                button2.Enabled = true;
                button1.Enabled = true;
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            if (System.Windows.Forms.DialogResult.OK == OpenTxtDialog.ShowDialog())
                richTextBox1.Text = System.IO.File.ReadAllText(OpenTxtDialog.FileName);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (System.Windows.Forms.DialogResult.OK == SaveTextDialog.ShowDialog())
                System.IO.File.WriteAllText(SaveTextDialog.FileName, richTextBox1.Text);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (System.Windows.Forms.DialogResult.OK == SaveImageDialog.ShowDialog())
                _tracer.Save(SaveImageDialog.FileName);
        }
    }
}